﻿namespace Leetcode.N0214;
public class Solution
{
    public string ShortestPalindrome(string s)
    {
        if (string.IsNullOrEmpty(s))
        {
            return string.Empty;
        }
        int findIndex = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (this.IsPalindromePairs(s, 0, i))
            {
                findIndex = i;
                continue;
            }
        }

        return new string(s.Substring(findIndex + 1).Reverse().ToArray()) + s;
    }

    private bool IsPalindromePairs(string word, int from, int to)
    {
        for (int i = from; i <= from + (to - from) / 2; i++)
        {
            if (word[i] != word[to - (i - from)])
            {
                return false;
            }
        }
        return true;
    }

}
